home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / var / lib / dpkg / info / x11-common.postrm < prev    next >
Encoding:
Text File  |  2007-04-02  |  32.1 KB  |  986 lines

  1. #!/bin/sh
  2. # Debian x11-common package post-removal script
  3. # Copyright 1998--2001, 2003 Branden Robinson.
  4. # Licensed under the GNU General Public License, version 2.  See the file
  5. # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
  6. # Acknowlegements to Stephen Early, Mark Eichin, and Manoj Srivastava.
  7.  
  8.  
  9. set -e
  10.  
  11. THIS_PACKAGE=x11-common
  12. THIS_SCRIPT=postrm
  13. CONFIG_DIR=/etc/X11
  14. XWRAPPER_CONFIG="$CONFIG_DIR/Xwrapper.config"
  15. CONFIG_AUX_DIR=/var/lib/x11
  16. XWRAPPER_CONFIG_CHECKSUM="$CONFIG_AUX_DIR/${XWRAPPER_CONFIG##*/}.md5sum"
  17. XWRAPPER_CONFIG_ROSTER="$CONFIG_AUX_DIR/${XWRAPPER_CONFIG##*/}.roster"
  18.  
  19. # $Id$
  20.  
  21. # This is the X Strike Force shell library for X Window System package
  22. # maintainer scripts.  It serves to define shell functions commonly used by
  23. # such packages, and performs some error checking necessary for proper operation
  24. # of those functions.  By itself, it does not "do" much; the maintainer scripts
  25. # invoke the functions defined here to accomplish package installation and
  26. # removal tasks.
  27.  
  28. # If you are reading this within a Debian package maintainer script (e.g.,
  29. # /var/lib/dpkg)info/PACKAGE.{config,preinst,postinst,prerm,postrm}), you can
  30. # skip past this library by scanning forward in this file to the string
  31. # "GOBSTOPPER".
  32.  
  33. SOURCE_VERSION=1:7.2-0ubuntu11
  34. OFFICIAL_BUILD=
  35.  
  36. # Use special abnormal exit codes so that problems with this library are more
  37. # easily tracked down.
  38. SHELL_LIB_INTERNAL_ERROR=86
  39. SHELL_LIB_THROWN_ERROR=74
  40. SHELL_LIB_USAGE_ERROR=99
  41.  
  42. # old -> new variable names
  43. if [ -z "$DEBUG_XORG_PACKAGE" ] && [ -n "$DEBUG_XFREE86_PACKAGE" ]; then
  44.   DEBUG_XORG_PACKAGE="$DEBUG_XFREE86_PACKAGE"
  45. fi
  46. if [ -z "$DEBUG_XORG_DEBCONF" ] && [ -n "$DEBUG_XFREE86_DEBCONF" ]; then
  47.   DEBUG_XORG_DEBCONF="$DEBUG_XFREE86_DEBCONF"
  48. fi
  49.  
  50. # initial sanity checks
  51. if [ -z "$THIS_PACKAGE" ]; then
  52.   cat >&2 <<EOF
  53. Error: package maintainer script attempted to use shell library without
  54. definining \$THIS_PACKAGE shell variable.  Please report the package name,
  55. version, and the text of this error message to the Debian Bug Tracking System.
  56. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  57. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  58. "doc-debian" package, or install the "reportbug" package and use the command of
  59. the same name to file a report against version $SOURCE_VERSION of this package.
  60. EOF
  61.   exit $SHELL_LIB_USAGE_ERROR
  62. fi
  63.  
  64. if [ -z "$THIS_SCRIPT" ]; then
  65.   cat >&2 <<EOF
  66. Error: package maintainer script attempted to use shell library without
  67. definining \$THIS_SCRIPT shell variable.  Please report the package name,
  68. version, and the text of this error message to the Debian Bug Tracking System.
  69. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  70. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  71. "doc-debian" package, or install the "reportbug" package and use the command of
  72. the same name to file a report against version $SOURCE_VERSION of the
  73. "$THIS_PACKAGE" package.
  74. EOF
  75.   exit $SHELL_LIB_USAGE_ERROR
  76. fi
  77.  
  78. ARCHITECTURE="$(dpkg --print-installation-architecture)"
  79.  
  80. LAPTOP=""
  81. if [ -n "$(which laptop-detect)" ]; then
  82.     if laptop-detect >/dev/null; then
  83.     LAPTOP=true
  84.     fi
  85. fi
  86.  
  87. if [ "$1" = "reconfigure" ] || [ -n "$DEBCONF_RECONFIGURE" ]; then
  88.   RECONFIGURE="true"
  89. else
  90.   RECONFIGURE=
  91. fi
  92.  
  93. if ([ "$1" = "install" ] || [ "$1" = "configure" ]) && [ -z "$2" ]; then
  94.   FIRSTINST="yes"
  95. fi
  96.  
  97. if [ -z "$RECONFIGURE" ] && [ -z "$FIRSTINST" ]; then
  98.   UPGRADE="yes"
  99. fi
  100.  
  101. trap "message;\
  102.       message \"Received signal.  Aborting $THIS_PACKAGE package $THIS_SCRIPT script.\";\
  103.       message;\
  104.       exit 1" HUP INT QUIT TERM
  105.  
  106. reject_nondigits () {
  107.   # syntax: reject_nondigits [ operand ... ]
  108.   #
  109.   # scan operands (typically shell variables whose values cannot be trusted) for
  110.   # characters other than decimal digits and barf if any are found
  111.   while [ -n "$1" ]; do
  112.     # does the operand contain anything but digits?
  113.     if ! expr "$1" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  114.       # can't use die(), because it wraps message() which wraps this function
  115.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_nondigits() encountered" \
  116.            "possibly malicious garbage \"$1\"" >&2
  117.       exit $SHELL_LIB_THROWN_ERROR
  118.     fi
  119.     shift
  120.   done
  121. }
  122.  
  123. reject_whitespace () {
  124.   # syntax: reject_whitespace [ operand ]
  125.   #
  126.   # scan operand (typically a shell variable whose value cannot be trusted) for
  127.   # whitespace characters and barf if any are found
  128.   if [ -n "$1" ]; then
  129.     # does the operand contain any whitespace?
  130.     if expr "$1" : "[[:space:]]" > /dev/null 2>&1; then
  131.       # can't use die(), because I want to avoid forward references
  132.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_whitespace() encountered" \
  133.            "possibly malicious garbage \"$1\"" >&2
  134.       exit $SHELL_LIB_THROWN_ERROR
  135.     fi
  136.   fi
  137. }
  138.  
  139. reject_unlikely_path_chars () {
  140.   # syntax: reject_unlikely_path_chars [ operand ... ]
  141.   #
  142.   # scan operands (typically shell variables whose values cannot be trusted) for
  143.   # characters unlikely to be seen in a path and which the shell might
  144.   # interpret and barf if any are found
  145.   while [ -n "$1" ]; do
  146.     # does the operand contain any funny characters?
  147.     if expr "$1" : '.*[!$&()*;<>?|].*' > /dev/null 2>&1; then
  148.       # can't use die(), because I want to avoid forward references
  149.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_unlikely_path_chars()" \
  150.            "encountered possibly malicious garbage \"$1\"" >&2
  151.       exit $SHELL_LIB_THROWN_ERROR
  152.     fi
  153.     shift
  154.   done
  155. }
  156.  
  157. # Query the terminal to establish a default number of columns to use for
  158. # displaying messages to the user.  This is used only as a fallback in the
  159. # event the COLUMNS variable is not set.  ($COLUMNS can react to SIGWINCH while
  160. # the script is running, and this cannot, only being calculated once.)
  161. DEFCOLUMNS=$(stty size 2> /dev/null | awk '{print $2}') || true
  162. if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  163.   DEFCOLUMNS=80
  164. fi
  165.  
  166. message () {
  167.   # pretty-print messages of arbitrary length
  168.   reject_nondigits "$COLUMNS"
  169.   echo "$*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS} >&2
  170. }
  171.  
  172. observe () {
  173.   # syntax: observe message ...
  174.   #
  175.   # issue observational message suitable for logging someday when support for
  176.   # it exists in dpkg
  177.   if [ -n "$DEBUG_XORG_PACKAGE" ]; then
  178.     message "$THIS_PACKAGE $THIS_SCRIPT note: $*"
  179.   fi
  180. }
  181.  
  182. warn () {
  183.   # syntax: warn message ...
  184.   #
  185.   # issue warning message suitable for logging someday when support for
  186.   # it exists in dpkg; also send to standard error
  187.   message "$THIS_PACKAGE $THIS_SCRIPT warning: $*"
  188. }
  189.  
  190. die () {
  191.   # syntax: die message ...
  192.   #
  193.   # exit script with error message
  194.   message "$THIS_PACKAGE $THIS_SCRIPT error: $*"
  195.   exit $SHELL_LIB_THROWN_ERROR
  196. }
  197.  
  198. internal_error () {
  199.   # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
  200.   message "internal error: $*"
  201.   if [ -n "$OFFICIAL_BUILD" ]; then
  202.     message "Please report a bug in the $THIS_SCRIPT script of the" \
  203.             "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  204.             "Tracking System.  Include all messages above that mention the" \
  205.             "$THIS_PACKAGE package.  Visit " \
  206.             "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  207.             "instructions, read the file" \
  208.             "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  209.             "package, or install the reportbug package and use the command of" \
  210.             "the same name to file a report."
  211.   fi
  212.   exit $SHELL_LIB_INTERNAL_ERROR
  213. }
  214.  
  215. usage_error () {
  216.   message "usage error: $*"
  217.   message "Please report a bug in the $THIS_SCRIPT script of the" \
  218.           "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  219.           "Tracking System.  Include all messages above that mention the" \
  220.           "$THIS_PACKAGE package.  Visit " \
  221.           "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  222.           "instructions, read the file" \
  223.           "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  224.           "package, or install the reportbug package and use the command of" \
  225.           "the same name to file a report."
  226.   exit $SHELL_LIB_USAGE_ERROR
  227. }
  228.  
  229.  
  230. maplink () {
  231.   # returns what symlink should point to; i.e., what the "sane" answer is
  232.   # Keep this in sync with the debian/*.links files.
  233.   # This is only needed for symlinks to directories.
  234.   #
  235.   # XXX: Most of these look wrong in the X11R7 world and need to be fixed.
  236.   # If we've stopped using this function, fixing it might enable us to re-enable
  237.   # it again and catch more errors.
  238.   case "$1" in
  239.     /etc/X11/xkb/compiled) echo /var/lib/xkb ;;
  240.     /etc/X11/xkb/xkbcomp) echo /usr/X11R6/bin/xkbcomp ;;
  241.     /usr/X11R6/lib/X11/app-defaults) echo /etc/X11/app-defaults ;;
  242.     /usr/X11R6/lib/X11/fs) echo /etc/X11/fs ;;
  243.     /usr/X11R6/lib/X11/lbxproxy) echo /etc/X11/lbxproxy ;;
  244.     /usr/X11R6/lib/X11/proxymngr) echo /etc/X11/proxymngr ;;
  245.     /usr/X11R6/lib/X11/rstart) echo /etc/X11/rstart ;;
  246.     /usr/X11R6/lib/X11/twm) echo /etc/X11/twm ;;
  247.     /usr/X11R6/lib/X11/xdm) echo /etc/X11/xdm ;;
  248.     /usr/X11R6/lib/X11/xinit) echo /etc/X11/xinit ;;
  249.     /usr/X11R6/lib/X11/xkb) echo /etc/X11/xkb ;;
  250.     /usr/X11R6/lib/X11/xserver) echo /etc/X11/xserver ;;
  251.     /usr/X11R6/lib/X11/xsm) echo /etc/X11/xsm ;;
  252.     /usr/bin/X11) echo ../X11R6/bin ;;
  253.     /usr/bin/rstartd) echo ../X11R6/bin/rstartd ;;
  254.     /usr/include/X11) echo ../X11R6/include/X11 ;;
  255.     /usr/lib/X11) echo ../X11R6/lib/X11 ;;
  256.     *) internal_error "maplink() called with unknown path \"$1\"" ;;
  257.   esac
  258. }
  259.  
  260. analyze_path () {
  261.   # given a supplied set of pathnames, break each one up by directory and do an
  262.   # ls -dl on each component, cumulatively; i.e.
  263.   # analyze_path /usr/X11R6/bin -> ls -dl /usr /usr/X11R6 /usr/X11R6/bin
  264.   # Thanks to Randolph Chung for this clever hack.
  265.  
  266.   #local f g
  267.  
  268.   while [ -n "$1" ]; do
  269.     reject_whitespace "$1"
  270.     _g=
  271.     message "Analyzing $1:"
  272.     for _f in $(echo "$1" | tr / \  ); do
  273.       if [ -e /$_g$_f ]; then
  274.         ls -dl /$_g$_f /$_g$_f.dpkg-* 2> /dev/null || true
  275.         _g=$_g$_f/
  276.       else
  277.         message "/$_g$_f: nonexistent; directory contents of /$_g:"
  278.         ls -l /$_g
  279.         break
  280.       fi
  281.     done
  282.     shift
  283.   done
  284. }
  285.  
  286. find_culprits () {
  287.   #local f p dpkg_info_dir possible_culprits smoking_guns bad_packages package \
  288.   #  msg
  289.  
  290.   reject_whitespace "$1"
  291.   message "Searching for overlapping packages..."
  292.   _dpkg_info_dir=/var/lib/dpkg/info
  293.   if [ -d $_dpkg_info_dir ]; then
  294.     if [ "$(echo $_dpkg_info_dir/*.list)" != "$_dpkg_info_dir/*.list" ]; then
  295.       _possible_culprits=$(ls -1 $_dpkg_info_dir/*.list | egrep -v \
  296.         "(xbase-clients|x11-common|xfs|xlibs)")
  297.       if [ -n "$_possible_culprits" ]; then
  298.         _smoking_guns=$(grep -l "$1" $_possible_culprits || true)
  299.         if [ -n "$_smoking_guns" ]; then
  300.           _bad_packages=$(printf "\\n")
  301.           for f in $_smoking_guns; do
  302.             # too bad you can't nest parameter expansion voodoo
  303.             p=${f%*.list}      # strip off the trailing ".list"
  304.             _package=${p##*/}   # strip off the directories
  305.             _bad_packages=$(printf "%s\n%s" "$_bad_packages" "$_package")
  306.           done
  307.           _msg=$(cat <<EOF
  308. The following packages appear to have file overlaps with the X.Org packages;
  309. these packages are either very old, or in violation of Debian Policy.  Try
  310. upgrading each of these packages to the latest available version if possible:
  311. for example, with the command "apt-get install".  If no newer version of a
  312. package is available, you will have to remove it; for example, with the command
  313. "apt-get remove".  If even the latest available version of the package has
  314. this file overlap, please file a bug against that package with the Debian Bug
  315. Tracking System.  You may want to refer the package maintainer to section 12.8
  316. of the Debian Policy manual.
  317. EOF
  318. )
  319.           message "$_msg"
  320.           message "The overlapping packages are: $_bad_packages"
  321.         else
  322.           message "no overlaps found."
  323.         fi
  324.       fi
  325.     else
  326.       message "cannot search; no matches for $_dpkg_info_dir/*.list."
  327.     fi
  328.   else
  329.     message "cannot search; $_dpkg_info_dir does not exist."
  330.   fi
  331. }
  332.  
  333. # we require a readlink command or shell function
  334. if ! which readlink > /dev/null 2>&1; then
  335.   message "The readlink command was not found.  Please install version" \
  336.           "1.13.1 or later of the debianutils package."
  337.   readlink () {
  338.     # returns what symlink in $1 actually points to
  339.     perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' "$1"
  340.   }
  341. fi
  342.  
  343. check_symlink () {
  344.   # syntax: check_symlink symlink
  345.   #
  346.   # See if specified symlink points where it is supposed to.  Return 0 if it
  347.   # does, and 1 if it does not.
  348.   #
  349.   # Primarily used by check_symlinks_and_warn() and check_symlinks_and_bomb().
  350.  
  351.   #local symlink
  352.  
  353.   # validate arguments
  354.   if [ $# -ne 1 ]; then
  355.     usage_error "check_symlink() called with wrong number of arguments;" \
  356.                 "expected 1, got $#"
  357.     exit $SHELL_LIB_USAGE_ERROR
  358.   fi
  359.  
  360.   _symlink="$1"
  361.  
  362.   if [ "$(maplink "$_symlink")" = "$(readlink "$_symlink")" ]; then
  363.     return 0
  364.   else
  365.     return 1
  366.   fi
  367. }
  368.  
  369. check_symlinks_and_warn () {
  370.   # syntax: check_symlinks_and_warn symlink ...
  371.   #
  372.   # For each argument, check for symlink sanity, and warn if it isn't sane.
  373.   #
  374.   # Call this function from a preinst script in the event $1 is "upgrade" or
  375.   # "install".
  376.  
  377.   #local errmsg symlink
  378.  
  379.   # validate arguments
  380.   if [ $# -lt 1 ]; then
  381.     usage_error "check_symlinks_and_warn() called with wrong number of" \
  382.                 "arguments; expected at least 1, got $#"
  383.     exit $SHELL_LIB_USAGE_ERROR
  384.   fi
  385.  
  386.   while [ -n "$1" ]; do
  387.     _symlink="$1"
  388.     if [ -L "$_symlink" ]; then
  389.       if ! check_symlink "$_symlink"; then
  390.         observe "$_symlink symbolic link points to wrong location" \
  391.                 "$(readlink "$_symlink"); removing"
  392.         rm "$_symlink"
  393.       fi
  394.     elif [ -e "$_symlink" ]; then
  395.       _errmsg="$_symlink exists and is not a symbolic link; this package cannot"
  396.       _errmsg="$_errmsg be installed until this"
  397.       if [ -f "$_symlink" ]; then
  398.         _errmsg="$_errmsg file"
  399.       elif [ -d "$_symlink" ]; then
  400.         _errmsg="$_errmsg directory"
  401.       else
  402.         _errmsg="$_errmsg thing"
  403.       fi
  404.       _errmsg="$_errmsg is removed"
  405.       die "$_errmsg"
  406.     fi
  407.     shift
  408.   done
  409. }
  410.  
  411. check_symlinks_and_bomb () {
  412.   # syntax: check_symlinks_and_bomb symlink ...
  413.   #
  414.   # For each argument, check for symlink sanity, and bomb if it isn't sane.
  415.   #
  416.   # Call this function from a postinst script.
  417.  
  418.   #local problem symlink
  419.  
  420.   # validate arguments
  421.   if [ $# -lt 1 ]; then
  422.     usage_error "check_symlinks_and_bomb() called with wrong number of"
  423.                 "arguments; expected at least 1, got $#"
  424.     exit $SHELL_LIB_USAGE_ERROR
  425.   fi
  426.  
  427.   while [ -n "$1" ]; do
  428.     _problem=
  429.     _symlink="$1"
  430.     if [ -L "$_symlink" ]; then
  431.       if ! check_symlink "$_symlink"; then
  432.         _problem=yes
  433.         warn "$_symlink symbolic link points to wrong location" \
  434.              "$(readlink "$_symlink")"
  435.       fi
  436.     elif [ -e "$_symlink" ]; then
  437.       _problem=yes
  438.       warn "$_symlink is not a symbolic link"
  439.     else
  440.       _problem=yes
  441.       warn "$_symlink symbolic link does not exist"
  442.     fi
  443.     if [ -n "$_problem" ]; then
  444.       analyze_path "$_symlink" "$(readlink "$_symlink")"
  445.       find_culprits "$_symlink"
  446.       die "bad symbolic links on system"
  447.     fi
  448.     shift
  449.   done
  450. }
  451.  
  452. font_update () {
  453.   # run $UPDATECMDS in $FONTDIRS
  454.  
  455.   #local dir cmd shortcmd x_font_dir_prefix
  456.  
  457.   _x_font_dir_prefix="/usr/share/fonts/X11"
  458.  
  459.   if [ -z "$UPDATECMDS" ]; then
  460.     usage_error "font_update() called but \$UPDATECMDS not set"
  461.   fi
  462.   if [ -z "$FONTDIRS" ]; then
  463.     usage_error "font_update() called but \$FONTDIRS not set"
  464.   fi
  465.  
  466.   reject_unlikely_path_chars "$UPDATECMDS"
  467.   reject_unlikely_path_chars "$FONTDIRS"
  468.  
  469.   for _dir in $FONTDIRS; do
  470.     if [ -d "$_x_font_dir_prefix/$_dir" ]; then
  471.       for _cmd in $UPDATECMDS; do
  472.         if which "$_cmd" > /dev/null 2>&1; then
  473.           _shortcmd=${_cmd##*/}
  474.           observe "running $_shortcmd in $_dir font directory"
  475.       _cmd_opts=
  476.           if [ "$_shortcmd" = "update-fonts-alias" ]; then
  477.             _cmd_opts=--x11r7-layout
  478.           fi
  479.           if [ "$_shortcmd" = "update-fonts-dir" ]; then
  480.             _cmd_opts=--x11r7-layout
  481.           fi
  482.           if [ "$_shortcmd" = "update-fonts-scale" ]; then
  483.             _cmd_opts=--x11r7-layout
  484.           fi
  485.           $_cmd $_cmd_opts $_dir || warn "$_cmd $_cmd_opts $_dir" \
  486.                               "failed; font directory data may not" \
  487.                               "be up to date"
  488.         else
  489.           warn "$_cmd not found; not updating corresponding $_dir font" \
  490.                "directory data"
  491.         fi
  492.       done
  493.     else
  494.       warn "$_dir is not a directory; not updating font directory data"
  495.     fi
  496.   done
  497. }
  498.  
  499. remove_conffile_prepare () {
  500.   # syntax: remove_conffile_prepare filename official_md5sum ...
  501.   #
  502.   # Check a conffile "filename" against a list of canonical MD5 checksums.
  503.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  504.   # operands provided, then prepare the conffile for removal from the system.
  505.   # We defer actual deletion until the package is configured so that we can
  506.   # roll this operation back if package installation fails.
  507.   #
  508.   # Call this function from a preinst script in the event $1 is "upgrade" or
  509.   # "install" and verify $2 to ensure the package is being upgraded from a
  510.   # version (or installed over a version removed-but-not-purged) prior to the
  511.   # one in which the conffile was obsoleted.
  512.  
  513.   #local conffile current_checksum
  514.  
  515.   # validate arguments
  516.   if [ $# -lt 2 ]; then
  517.     usage_error "remove_conffile_prepare() called with wrong number of" \
  518.                 "arguments; expected at least 2, got $#"
  519.     exit $SHELL_LIB_USAGE_ERROR
  520.   fi
  521.  
  522.   _conffile="$1"
  523.   shift
  524.  
  525.   # does the _conffile even exist?
  526.   if [ -e "$_conffile" ]; then
  527.     # calculate its checksum
  528.     _current_checksum=$(md5sum < "$_conffile" | sed 's/[[:space:]].*//')
  529.     # compare it to each supplied checksum
  530.     while [ -n "$1" ]; do
  531.       if [ "$_current_checksum" = "$1" ]; then
  532.         # we found a match; move the confffile and stop looking
  533.         observe "preparing obsolete conffile $_conffile for removal"
  534.         mv "$_conffile" "$_conffile.$THIS_PACKAGE-tmp"
  535.         break
  536.       fi
  537.       shift
  538.     done
  539.   fi
  540. }
  541.  
  542. remove_conffile_commit () {
  543.   # syntax: remove_conffile_commit filename
  544.   #
  545.   # Complete the removal of a conffile "filename" that has become obsolete.
  546.   #
  547.   # Call this function from a postinst script after having used
  548.   # remove_conffile_prepare() in the preinst.
  549.  
  550.   #local conffile
  551.  
  552.   # validate arguments
  553.   if [ $# -ne 1 ]; then
  554.     usage_error "remove_conffile_commit() called with wrong number of" \
  555.                 "arguments; expected 1, got $#"
  556.     exit $SHELL_LIB_USAGE_ERROR
  557.   fi
  558.  
  559.   _conffile="$1"
  560.  
  561.   # if the temporary file created by remove_conffile_prepare() exists, remove it
  562.   if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
  563.     observe "committing removal of obsolete conffile $_conffile"
  564.     rm "$_conffile.$THIS_PACKAGE-tmp"
  565.   fi
  566. }
  567.  
  568. remove_conffile_rollback () {
  569.   # syntax: remove_conffile_rollback filename
  570.   #
  571.   # Roll back the removal of a conffile "filename".
  572.   #
  573.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  574.   # or "abort-install" is  after having used remove_conffile_prepare() in the
  575.   # preinst.
  576.  
  577.   #local conffile
  578.  
  579.   # validate arguments
  580.   if [ $# -ne 1 ]; then
  581.     usage_error "remove_conffile_rollback() called with wrong number of" \
  582.                 "arguments; expected 1, got $#"
  583.     exit $SHELL_LIB_USAGE_ERROR
  584.   fi
  585.  
  586.   _conffile="$1"
  587.  
  588.   # if the temporary file created by remove_conffile_prepare() exists, move it
  589.   # back
  590.   if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
  591.     observe "rolling back removal of obsolete conffile $_conffile"
  592.     mv "$_conffile.$THIS_PACKAGE-tmp" "$_conffile"
  593.   fi
  594. }
  595.  
  596. replace_conffile_with_symlink_prepare () {
  597.   # syntax: replace_conffile_with_symlink_prepare oldfilename newfilename \
  598.   # official_md5sum ...
  599.   #
  600.   # Check a conffile "oldfilename" against a list of canonical MD5 checksums.
  601.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  602.   # operands provided, then prepare the conffile for removal from the system.
  603.   # We defer actual deletion until the package is configured so that we can
  604.   # roll this operation back if package installation fails. Otherwise copy it
  605.   # to newfilename and let dpkg handle it through conffiles mechanism.
  606.   #
  607.   # Call this function from a preinst script in the event $1 is "upgrade" or
  608.   # "install" and verify $2 to ensure the package is being upgraded from a
  609.   # version (or installed over a version removed-but-not-purged) prior to the
  610.   # one in which the conffile was obsoleted.
  611.  
  612.   #local conffile current_checksum
  613.  
  614.   # validate arguments
  615.   if [ $# -lt 3 ]; then
  616.     usage_error "replace_conffile_with_symlink_prepare() called with wrong" \
  617.                 " number of arguments; expected at least 3, got $#"
  618.     exit $SHELL_LIB_USAGE_ERROR
  619.   fi
  620.  
  621.   _oldconffile="$1"
  622.   shift
  623.   _newconffile="$1"
  624.   shift
  625.  
  626.   remove_conffile_prepare "$_oldconffile" "$@"
  627.   # If $_oldconffile still exists, then md5sums didn't match.
  628.   # Copy it to new one.
  629.   if [ -f "$_oldconffile" ]; then
  630.     cp "$_oldconffile" "$_newconffile"
  631.   fi
  632.  
  633. }
  634.  
  635. replace_conffile_with_symlink_commit () {
  636.   # syntax: replace_conffile_with_symlink_commit oldfilename
  637.   #
  638.   # Complete the removal of a conffile "oldfilename" that has been
  639.   # replaced by a symlink.
  640.   #
  641.   # Call this function from a postinst script after having used
  642.   # replace_conffile_with_symlink_prepare() in the preinst.
  643.  
  644.   #local conffile
  645.  
  646.   # validate arguments
  647.   if [ $# -ne 1 ]; then
  648.     usage_error "replace_conffile_with_symlink_commit() called with wrong" \
  649.                 "number of arguments; expected 1, got $#"
  650.     exit $SHELL_LIB_USAGE_ERROR
  651.   fi
  652.  
  653.   _conffile="$1"
  654.  
  655.   remove_conffile_commit "$_conffile"
  656. }
  657.  
  658. replace_conffile_with_symlink_rollback () {
  659.   # syntax: replace_conffile_with_symlink_rollback oldfilename newfilename
  660.   #
  661.   # Roll back the replacing of a conffile "oldfilename" with symlink to
  662.   # "newfilename".
  663.   #
  664.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  665.   # or "abort-install" and verify $2 to ensure the package failed to upgrade
  666.   # from a version (or install over a version removed-but-not-purged) prior
  667.   # to the one in which the conffile was obsoleted.
  668.   # You should have  used replace_conffile_with_symlink_prepare() in the
  669.   # preinst.
  670.  
  671.   #local conffile
  672.  
  673.   # validate arguments
  674.   if [ $# -ne 2 ]; then
  675.     usage_error "replace_conffile_with_symlink_rollback() called with wrong" \
  676.                 "number of arguments; expected 2, got $#"
  677.     exit $SHELL_LIB_USAGE_ERROR
  678.   fi
  679.  
  680.   _oldconffile="$1"
  681.   _newconffile="$2"
  682.  
  683.   remove_conffile_rollback "$_oldconffile"
  684.   if [ -f "$_newconffile" ]; then
  685.     rm "$_newconffile"
  686.   fi
  687. }
  688.  
  689. run () {
  690.   # syntax: run command [ argument ... ]
  691.   #
  692.   # Run specified command with optional arguments and report its exit status.
  693.   # Useful for commands whose exit status may be nonzero, but still acceptable,
  694.   # or commands whose failure is not fatal to us.
  695.   #
  696.   # NOTE: Do *not* use this function with db_get or db_metaget commands; in
  697.   # those cases the return value of the debconf command *must* be checked
  698.   # before the string returned by debconf is used for anything.
  699.  
  700.   #local retval
  701.  
  702.   # validate arguments
  703.   if [ $# -lt 1 ]; then
  704.     usage_error "run() called with wrong number of arguments; expected at" \
  705.                 "least 1, got $#"
  706.     exit $SHELL_LIB_USAGE_ERROR
  707.   fi
  708.  
  709.   "$@" || _retval=$?
  710.  
  711.   if [ ${_retval:-0} -ne 0 ]; then
  712.     observe "command \"$*\" exited with status $_retval"
  713.   fi
  714. }
  715.  
  716. register_x_lib_dir_with_ld_so () {
  717.   # syntax: register_x_lib_dir_with_ld_so
  718.   #
  719.   # Configure the dynamic loader ld.so to search /usr/X11R6/lib for shared
  720.   # libraries.
  721.   #
  722.   # Call this function from the postinst script of a package that places a
  723.   # shared library in /usr/X11R6/lib, before invoking ldconfig.
  724.  
  725.   #local dir ldsoconf
  726.  
  727.   _dir="/usr/X11R6/lib"
  728.   _ldsoconf="/etc/ld.so.conf"
  729.  
  730.   # is the line not already present?
  731.   if ! fgrep -qsx "$_dir" "$_ldsoconf"; then
  732.     observe "adding $_dir directory to $_ldsoconf"
  733.     echo "$_dir" >> "$_ldsoconf"
  734.   fi
  735. }
  736.  
  737. deregister_x_lib_dir_with_ld_so () {
  738.   # syntax: deregister_x_lib_dir_with_ld_so
  739.   #
  740.   # Configure dynamic loader ld.so to not search /usr/X11R6/lib for shared
  741.   # libraries, if and only if no shared libaries remain there.
  742.   #
  743.   # Call this function from the postrm script of a package that places a shared
  744.   # library in /usr/X11R6/lib, in the event "$1" is "remove", and before
  745.   # invoking ldconfig.
  746.  
  747.   #local dir ldsoconf fgrep_status cmp_status
  748.  
  749.   _dir="/usr/X11R6/lib"
  750.   _ldsoconf="/etc/ld.so.conf"
  751.  
  752.   # is the line present?
  753.   if fgrep -qsx "$_dir" "$_ldsoconf"; then
  754.     # are there any shared objects in the directory?
  755.     if [ "$(echo "$_dir"/lib*.so.*.*)" = "$_dir/lib*.so.*.*" ]; then
  756.       # glob expansion produced nothing, so no shared libraries are present
  757.       observe "removing $_dir directory from $_ldsoconf"
  758.       # rewrite the file (very carefully)
  759.       set +e
  760.       fgrep -svx "$_dir" "$_ldsoconf" > "$_ldsoconf.dpkg-tmp"
  761.       _fgrep_status=$?
  762.       set -e
  763.       case $_fgrep_status in
  764.         0|1) ;; # we don't actually care if any lines matched or not
  765.         *) die "error reading \"$_ldsoconf\"; fgrep exited with status" \
  766.           "$_fgrep_status" ;;
  767.       esac
  768.       set +e
  769.       cmp -s "$_ldsoconf.dpkg-tmp" "$_ldsoconf"
  770.       _cmp_status=$?
  771.       set -e
  772.       case $_cmp_status in
  773.         0) rm "$_ldsoconf.dpkg-tmp" ;; # files are identical
  774.         1) mv "$_ldsoconf.dpkg-tmp" "$_ldsoconf" ;; # files differ
  775.         *) die "error comparing \"$_ldsoconf.dpkg-tmp\" to \"$_ldsoconf\";" \
  776.           "cmp exited with status $_cmp_status" ;;
  777.       esac
  778.     fi
  779.   fi
  780. }
  781.  
  782. make_symlink_sane () {
  783.   # syntax: make_symlink_sane symlink target
  784.   #
  785.   # Ensure that the symbolic link symlink exists, and points to target.
  786.   #
  787.   # If symlink does not exist, create it and point it at target.
  788.   #
  789.   # If symlink exists but is not a symbolic link, back it up.
  790.   #
  791.   # If symlink exists, is a symbolic link, but points to the wrong location, fix
  792.   # it.
  793.   #
  794.   # If symlink exists, is a symbolic link, and already points to target, do
  795.   # nothing.
  796.   #
  797.   # This function wouldn't be needed if ln had an -I, --idempotent option.
  798.  
  799.   # Validate arguments.
  800.   if [ $# -ne 2 ]; then
  801.     usage_error "make_symlink_sane() called with wrong number of arguments;" \
  802.       "expected 2, got $#"
  803.     exit $SHELL_LIB_USAGE_ERROR
  804.   fi
  805.  
  806.   # We could just use the positional parameters as-is, but that makes things
  807.   # harder to follow.
  808.   #local symlink target
  809.  
  810.   _symlink="$1"
  811.   _target="$2"
  812.  
  813.   if [ -L "$_symlink" ] && [ "$(readlink "$_symlink")" = "$_target" ]; then
  814.       observe "link from $_symlink to $_target already exists"
  815.   else
  816.     observe "creating symbolic link from $_symlink to $_target"
  817.     mkdir -p "${_target%/*}" "${_symlink%/*}"
  818.     ln -s -b -S ".dpkg-old" "$_target" "$_symlink"
  819.   fi
  820. }
  821.  
  822. migrate_dir_to_symlink () {
  823.   # syntax: migrate_dir_to_symlink old_location new_location
  824.   #
  825.   # Per Debian Policy section 6.5.4, "A directory will never be replaced by a
  826.   # symbolic link to a directory or vice versa; instead, the existing state
  827.   # (symlink or not) will be left alone and dpkg will follow the symlink if
  828.   # there is one."
  829.   #
  830.   # We have to do it ourselves.
  831.   #
  832.   # This function moves the contents of old_location, a directory, into
  833.   # new_location, a directory, then makes old_location a symbolic link to
  834.   # new_location.
  835.   #
  836.   # old_location need not exist, but if it does, it must be a directory (or a
  837.   # symlink to a directory).  If it is not, it is backed up.  If new_location
  838.   # exists already and is not a directory, it is backed up.
  839.   #
  840.   # This function should be called from a package's preinst so that other
  841.   # packages unpacked after this one --- but before this package's postinst runs
  842.   # --- are unpacked into new_location even if their payloads contain
  843.   # old_location filespecs.
  844.  
  845.   # Validate arguments.
  846.   if [ $# -ne 2 ]; then
  847.     usage_error "migrate_dir_to_symlink() called with wrong number of"
  848.                 "arguments; expected 2, got $#"
  849.     exit $SHELL_LIB_USAGE_ERROR
  850.   fi
  851.  
  852.   # We could just use the positional parameters as-is, but that makes things
  853.   # harder to follow.
  854.   local _new _old
  855.  
  856.   _old="$1"
  857.   _new="$2"
  858.  
  859.   # Is old location a symlink?
  860.   if [ -L "$_old" ]; then
  861.     # Does it already point to new location?
  862.     if [ "$(readlink "$_old")" = "$_new" ]; then
  863.       # Nothing to do; migration has already been done.
  864.       observe "migration of $_old to $_new already done"
  865.       return 0
  866.     else
  867.       # Back it up.
  868.       warn "backing up symbolic link $_old as $_old.dpkg-old"
  869.       mv -b "$_old" "$_old.dpkg-old"
  870.     fi
  871.   fi
  872.  
  873.   # Does old location exist, but is not a directory?
  874.   if [ -e "$_old" ] && ! [ -d "$_old" ]; then
  875.       # Back it up.
  876.       warn "backing up non-directory $_old as $_old.dpkg-old"
  877.       mv -b "$_old" "$_old.dpkg-old"
  878.   fi
  879.  
  880.   observe "migrating $_old to $_new"
  881.  
  882.   # Is new location a symlink?
  883.   if [ -L "$_new" ]; then
  884.     # Does it point the wrong way, i.e., back to where we're migrating from?
  885.     if [ "$(readlink "$_new")" = "$_old" ]; then
  886.       # Get rid of it.
  887.       observe "removing symbolic link $_new which points to $_old"
  888.       rm "$_new"
  889.     else
  890.       # Back it up.
  891.       warn "backing up symbolic link $_new as $_new.dpkg-old"
  892.       mv -b "$_new" "$_new.dpkg-old"
  893.     fi
  894.   fi
  895.  
  896.   # Does new location exist, but is not a directory?
  897.   if [ -e "$_new" ] && ! [ -d "$_new" ]; then
  898.     warn "backing up non-directory $_new as $_new.dpkg-old"
  899.     mv -b "$_new" "$_new.dpkg-old"
  900.   fi
  901.  
  902.   # Create new directory if it does not yet exist.
  903.   if ! [ -e "$_new" ]; then
  904.     observe "creating $_new"
  905.     mkdir -p "$_new"
  906.   fi
  907.  
  908.   # Copy files in old location to new location.  Back up any filenames that
  909.   # already exist in the new location with the extension ".dpkg-old".
  910.   observe "copying files from $_old to $_new"
  911.   if ! (cd "$_old" && cp -a -b -S ".dpkg-old" . "$_new"); then
  912.     die "error(s) encountered while copying files from $_old to $_new"
  913.   fi
  914.  
  915.   # Remove files at old location.
  916.   observe "removing $_old"
  917.   rm -r "$_old"
  918.  
  919.   # Create symlink from old location to new location.
  920.   make_symlink_sane "$_old" "$_new"
  921. }
  922.  
  923. # vim:set ai et sw=2 ts=2 tw=80:
  924.  
  925. # GOBSTOPPER: The X Strike Force shell library ends here.
  926.  
  927. # clean up non-conffile configuration files and related materials on purge
  928. if [ "$1" = "purge" ]; then
  929.   # de-register this package as a handler of the X server wrapper config file
  930.   if [ -e "$XWRAPPER_CONFIG_ROSTER" ]; then
  931.     # check existing roster file for our package name
  932.     if fgrep -qx "$THIS_PACKAGE" "$XWRAPPER_CONFIG_ROSTER" 2>/dev/null; then
  933.       # construct temporary roster file with our package name removed, ignoring
  934.       # failure
  935.       fgrep -vx "$THIS_PACKAGE" "$XWRAPPER_CONFIG_ROSTER" > \
  936.         "$XWRAPPER_CONFIG_ROSTER.dpkg-tmp" 2>/dev/null || true
  937.       # is there anything left?
  938.       if [ -s "$XWRAPPER_CONFIG_ROSTER.dpkg-tmp" ]; then
  939.         # yes, replace the roster file
  940.         mv "$XWRAPPER_CONFIG_ROSTER.dpkg-tmp" "$XWRAPPER_CONFIG_ROSTER"
  941.       else
  942.         # no; remove both the roster and our temporary copy
  943.         rm -f "$XWRAPPER_CONFIG_ROSTER" "$XWRAPPER_CONFIG_ROSTER.dpkg-tmp"
  944.         # remove X server wrapper config file if it was still managed by the
  945.         # package
  946.         if [ -e "$XWRAPPER_CONFIG_CHECKSUM" ]; then
  947.           # does it exist?
  948.           if [ -e "$XWRAPPER_CONFIG" ]; then
  949.             # does the current MD5 checksum match the stored checksum?
  950.             if [ "$(md5sum "$XWRAPPER_CONFIG")" \
  951.                  = "$(cat "$XWRAPPER_CONFIG_CHECKSUM")" ]; then
  952.               # yes; remove the config file
  953.               rm -f "$XWRAPPER_CONFIG"
  954.             fi
  955.           fi
  956.           # remove the checksum file; any remaining X server wrapper config file
  957.           # still on the system at this point is no longer being managed (local
  958.           # user customization)
  959.           rm -f "$XWRAPPER_CONFIG_CHECKSUM"
  960.         fi
  961.       fi
  962.     fi
  963.   fi
  964.  
  965.   for DIR in "$CONFIG_DIR" "$CONFIG_AUX_DIR"; do
  966.       rmdir "$DIR" 2> /dev/null || true
  967.   done
  968. fi
  969.  
  970. # Automatically added by dh_installdebconf
  971. if [ "$1" = purge ] && [ -e /usr/share/debconf/confmodule ]; then
  972.     . /usr/share/debconf/confmodule
  973.     db_purge
  974. fi
  975. # End automatically added section
  976. # Automatically added by dh_installinit
  977. if [ "$1" = "purge" ] ; then
  978.     update-rc.d x11-common remove >/dev/null || exit $?
  979. fi
  980. # End automatically added section
  981.  
  982.  
  983. exit 0
  984.  
  985. # vim:set ai et sts=2 sw=2 tw=80:
  986.